<template>
    <div class="trigger-action-select-action">
        <div class="trigger-action-select-action-title">
            选择触发动作（支持多选）
        </div>
        <div class="trigger-action-select-action-item"
            :class="{ 'trigger-action-select-action-item-select': state.executeWay.options.actionList.some(item => item === i.bizActionCode) }"
            v-for="i in options.actionList" @click="actionClick(i)" :key="i.bizActionCode">
            <el-icon class="trigger-action-select-action-item-select-icon el-icon-check"
                v-if="state.executeWay.options.actionList.some(item => item == i.bizActionCode)"></el-icon>
            <div class="trigger-action-select-action-item-title">
                {{ i.bizActionName }}
            </div>
            <div class="trigger-action-select-action-item-info">
                {{ i.bizActionDesc }}
            </div>
        </div>
    </div>
</template>

<script>
import state from '@src/modules/trigger/view/setting/util/state.js'

export default {
    props: {
        options: {
            type: Object,
            default: () => {}
        }
    },
    data() {
        return {
            selectedActionList: [],
            actionList: [],
        }
    },
    computed: {
        state() {
            return state;
        }
    },
    created() {
        if (!state.executeWay?.options || !state.executeWay.options?.actionList) {
            this.$set(state.executeWay, 'options', {
                ...state.executeWay?.options,
                actionList: [],
            })
        }
        if (!state.currentTriggerInfo.eventWayInfo) {
            state.currentTriggerInfo.eventWayInfo = [];
        }
    },
    methods: {
        actionClick(item) {
            const index = state.executeWay.options.actionList.findIndex(i => i === item.bizActionCode);
            if (index > -1) {
                state.executeWay.options.actionList.splice(index, 1);
                state.currentTriggerInfo.eventWayInfo.splice(index, 1);
            } else {
                state.executeWay.options.actionList.push(item.bizActionCode);
                state.currentTriggerInfo.eventWayInfo.push(item.bizActionName);
            }
        }
    }
}
</script>

<style lang="scss" scoped>
.trigger-action-select-action {
    height: 100%;
    overflow: auto;
    &-title {
        font-size: 14px;
        margin: 4px 0 12px 0;
        height: 32px;
        line-height: 32px;
    }

    &-item {
        position: relative;
        margin-bottom: 16px;
        border-radius: 4px;
        border: 1px solid #E4E7ED;
        padding: 12px 16px;
        overflow: hidden;

        &-title {
            font-size: 14px;
            font-weight: 500;
        }

        &-info {
            font-size: 12px;
            color: #595959;
        }
    }

    &-item:hover {
        border-color: $color-primary;
        cursor: pointer;
    }

    &-item-select-icon {
        position: absolute;
        right: 2px;
        top: 2px;
        color: #fff;
        font-size: 16px;
    }

    &-item-select {
        border-color: $color-primary;
        background-color: var(--color-primary-light-1);
    }

    &-item-select::before {
        content: '';
        width: 0;
        height: 0;
        border-left: 24px solid transparent;
        border-right: 24px solid transparent;
        border-bottom: 24px solid $color-primary;
        position: absolute;
        right: -16px;
        top: -4px;
        transform: rotate(45deg);
    }
}
</style>